<template>
    <div class="shopSwiper">
        <div class="catShopList-container swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="goods in data" :key="goods.goods_id">
                    <img :src="goods.goods_thumb" alt="">
                    <div class="info">
                        <span class="title">{{ goods.goods_name }}</span>
                        <span class="newPrice">{{ goods.market_price }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Swiper from 'swiper'
export default {
    props: ['data'],
    data() {
        return {
            swiper: null
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.initSwiper()
        })
    },
    methods: {
        initSwiper() {
            this.swiper = new Swiper('.catShopList-container', {
                slidesPerView: 'auto',
                spaceBetween: 10,
                freeMode: true,
                freeModeSticky: true,
                observer: true, // 关键配置：监听 DOM 变化
                observeParents: true // 关键配置：监听父容器变化
            })
        },
    }

}
</script>

<style scoped>
.catShopList-container {
    display: flex;
    width: 100%;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
}

.catShopList-container .swiper-slide {
    width: 26.6667vw;
    display: flex;
    flex-direction: column;
    border-radius: 2.6667vw;
    overflow: hidden;

    .info {
        background-color: #fff;
    }
}

.catShopList-container img {
    width: 26.6667vw;
    height: 26.6667vw;
    border: 1px solid #ccc;
    border-radius: 2.6667vw;
    box-sizing: border-box;
}

.catShopList-container span {
    font-size: 3.2vw;
    display: block;
}

.catShopList-container .title {
    width: 26.6667vw;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
    line-height: 6.4vw;
    font-size: 3.7333vw;
    padding-left: 2.6667vw;
    box-sizing: border-box;
}

.catShopList-container .newPrice {
    color: red;
    font-weight: bold;
    font-size: 3.7333vw;
    line-height: 8vw;
    text-align: center;
}
</style>